<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>添加图书</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
	body {background: rgb(254,238,189);}
</style>
	  <script type="text/javascript" src="/adminjsps/js/jquery-3.2.1.min.js"></script>
  </head>
  
  <body>
    <h1>添加图书</h1>
    <p style="font-weight: 900; color: red">${msg }</p>
    <div>
    	图书名称：<input style="width: 150px; height: 20px;" type="text" name="bname"/><br/>
    	图书图片：<input style="width: 223px; height: 20px;" type="file" name="image"/><br/>
    	图书单价：<input style="width: 150px; height: 20px;" type="number" name="price"/><br/>
    	图书作者：<input style="width: 150px; height: 20px;" type="text" name="author"/><br/>
    	图书分类：<select style="width: 150px; height: 20px;" name="cid" id="select">
    		<%--<option value="">JavaSE</option>--%>
    		<%--<option value="">JavaEE</option>--%>
			<%--<option value="">JavaScript</option>--%>
			<%--<option value="">Hibernate</option>--%>
			<%--<option value="">Struts</option>--%>
			<%--<option value="">Spring</option>--%>
    	</select>
    	<br/>
    	<input type="button" value="添加图书" class="btn"/>
		<span id="span"></span>
    </div>
	<script>
		window.onload=function(){
			$.ajax({
				url:"/category",
				type:"get",
				success:function (re) {
					var i;
					for (i = 0; i < re.data.length; i++) {
						$("<option id='"+re.data[i].cid+"'>"+re.data[i].cname+"</option>")
								.appendTo("select")
					}

				}
			})
		}
		$(".btn").click(function () {
			var bname = $("input[name='bname']").val();
			var image = $("input[name='image']").val();
			var price = $("input[name='price']").val();
			var author = $("input[name='author']").val();
			var cname = $("#select").val();
			console.log(bname);
			console.log(cname);
			$.ajax({
				url:"/addbook",
				type:"get",
				data:{
					bname:bname,
					image:image,
					price:price,
					author:author,
					cname:cname
				},
				success:function (re) {
					// alert(re.msg)
					$("#span").html(re.msg)
				}
			})
		})
	</script>
  </body>
</html>
